package model

// Room represents the room of game
type Room struct {
	ID         int          `json:"id"`
	HostID     int          `json:"hostID"`
	PlayersID  []int        `json:"-"`
	Setting    *RoomSetting `json:"-"`
	PuzzleID   int          `json:"puzzleID"`
	RemainTime TimeDuration `json:"-"`
	Status     RoomStatus   `json:"status"`
}

// RoomChan is channel for room
type RoomChan <-chan Room

// RoomSetting represents the setting of a room
type RoomSetting struct {
	Mode       GameMode     `json:"mode"`
	MaxPlayer  int          `json:"maxPlayer"`
	Duration   TimeDuration `json:"duration"`
	Difficulty Difficulty   `json:"difficulty"`
}

// NewRoomSetting creates default RoomSetting
func NewRoomSetting() *RoomSetting {
	return &RoomSetting{
		Mode:       GameModeVersus,
		MaxPlayer:  4,
		Duration:   40 * 60 * TimeSecond,
		Difficulty: DifficultyEasy,
	}
}

// IsListUpdatedResRoom implenments interface ListUpdatedResRoom
// Like Union
func (Room) IsListUpdatedResRoom() {}

// NewRoomParam is param for NewRoom
type NewRoomParam struct {
	ID       int
	HostID   int
	PuzzleID int
}

// NewRoom Creates a room with config
func NewRoom(config NewRoomParam) *Room {
	setting := NewRoomSetting()
	r := &Room{
		ID:         config.ID,
		HostID:     config.HostID,
		PlayersID:  []int{config.HostID},
		PuzzleID:   config.PuzzleID,
		Setting:    setting,
		RemainTime: setting.Duration,
		Status:     RoomStatusWaiting,
	}
	return r
}
